import { postDeleteProject } from '../../../../api/index'
const app = getApp()

Component({
  properties: {
    item: {
      type: Object,
      value: {}
    },
    tabActive: {
      type: String,
      value: ''
    },
    teamActive: {
      type: String,
      value: ''
    }
  },
  data: {
    showHandles: false
  },
  methods: {
    seeDetail () {
      wx.$nav.navigateTo(`/pages/account/project/detail/index?id=${this.data.item.projectId}`)
    },
    selectHandle () {
      // this.setData({ showHandles: true })
      this.triggerEvent('showHandles', { show: true, item: this.data.item })
    },
    editProject () {
      wx.$nav.navigateTo(`/pages/account/project/edit/index?id=${this.data.item.projectId}`)
    },
    seeMember () {
      wx.$nav.navigateTo(`/pages/account/project/member/index?id=${this.data.item.projectId}`)
    },
    async deleteProject () {
      try {
        const { confirm } = await wx.$pro.showModal({ title: '提示', content: '确定要删除该项目嘛？',  })
        if (confirm) {
          await postDeleteProject({ projectId: this.data.item.projectId })
          wx.showToast({ title: '删除成功！', icon: 'none' })
          this.setData({ showHandles: false })
          this.triggerEvent('change')
        }
      } catch (err) {
        wx.showToast({ title: err.message || err.ResultSet.errors, icon: 'none' })
      }
    },
    cancel () {
      this.setData({ showHandles: false })
    }
  },
})